package com.zqs.mapper;

import com.zqs.entity.UsedCar;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UsedCarMapper {


    /**
     * 添加卖车信息
     * @param usedCar 车的基本信息
     * @return 返回影响的行数
     */
    @Insert("insert into t_usedcar(title,price,image,uid,detail,state,created_user,created_time,modified_user,modified_time) " +
            "values(#{title},#{price},#{image},#{uid},#{detail},#{state},#{createdUser}," +
            "#{createdTime},#{modifiedUser},#{modifiedTime})")
    Integer addUsedCar(UsedCar usedCar);

    /**
     * 根据uid查询用户卖的车
     * @param uid 用户id
     * @return 返回用户卖车的集合
     */
    @Select("select * from t_usedCar where uid = #{uid}")
    List<UsedCar> getByUid(Integer uid);

    /**
     * 查询所有的二手车用于展示
     * @return 返回所有二手车集合
     */
    @Select("select * from t_usedCar")
    List<UsedCar> getAll();


    @Update("update t_usedcar set state = 0 where id = #{id} and uid = #{uid}")
    Integer updateStateById(@Param("id") Integer id,@Param("uid") Integer uid);
}
